package com.jy.adscm.operation.aftersales.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jy.adscm.bean.system.JyUser;
import com.jy.adscm.operation.aftersales.bean.QueryShMachine;
import com.jy.adscm.operation.aftersales.bean.ShMachine;
import com.jy.adscm.operation.aftersales.mapper.mysql.ShMachineMapper;
import com.jy.adscm.operation.aftersales.service.ShMachineService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.jy.adscm.system.mapper.mysql.JyUserMapper;
import com.jy.adscm.utils.AdscmBaseUtils;
import com.jy.adscm.zltx.bean.JyDrawingType;
import com.jy.adscm.zltx.mapper.mysql.JyDrawingTypeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zyl
 * @since 2019-07-03
 */
@Service
public class ShMachineServiceImpl extends ServiceImpl<ShMachineMapper, ShMachine> implements ShMachineService {
   @Autowired
    JyUserMapper jyUserMapper;
   @Autowired
    JyDrawingTypeMapper jyDrawingTypeMapper;
    @Override
    public Page<ShMachine> selectAll(Page<ShMachine> page, QueryShMachine queryShMachine) {
        Wrapper<ShMachine> wrapper =new EntityWrapper<>();
        wrapper.eq("pid",queryShMachine.getPid());
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryShMachine.getFactoryCode(),null)){
            wrapper.like("factory_code",queryShMachine.getFactoryCode());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryShMachine.getStationCode(),null)){
            wrapper.like("station_code",queryShMachine.getStationCode());
        }
        if (AdscmBaseUtils.getInstance().isNotEmpty(queryShMachine.getState(),null)){
            wrapper.like("state",queryShMachine.getStationCode());
        }
        page = super.selectPage(page, wrapper);
        List<ShMachine> records = page.getRecords();
        for (ShMachine shMachine : records) {
            if (AdscmBaseUtils.getInstance().isNotEmpty(shMachine.getCreator(),null)){
                JyUser jyUser = jyUserMapper.selectById(shMachine.getCreator());
                shMachine.setCreatorName(jyUser.getName());
            }
           if (AdscmBaseUtils.getInstance().isNotEmpty(shMachine.getName(),null)){
               JyDrawingType jyDrawingType = jyDrawingTypeMapper.selectById(shMachine.getName());
               shMachine.setNameName(jyDrawingType);
           }

        }
        page.setTotal(super.selectCount(wrapper));
        return page;
    }

    @Override
    public List<ShMachine> selectByCid(Integer cid) {
       Wrapper<ShMachine> wrapper=new EntityWrapper<>();
       wrapper.eq("pid",cid);
        List<ShMachine> shMachines = selectList(wrapper);
        return shMachines;
    }
}
